package org.ucas.faker.web;

import org.ucas.faker.web.entity.patents.*;
import org.ucas.faker.web.fetcher.FetchReqBuilder;
import org.ucas.faker.web.fetcher.cond.CompCond;
import org.ucas.faker.web.fetcher.cond.FetchCond;
import org.ucas.faker.web.fetcher.meta.ConstantField;
import org.ucas.faker.web.fetcher.meta.ConstraintField;
import org.ucas.faker.web.fetcher.parse.TableMeta;
import org.ucas.faker.web.fetcher.parse.TableParser;
import org.ucas.faker.web.utils.wx.WxClient;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class TestMain {

  private static void prepare() {
    TableParser parser = new TableParser(FetchReqBuilder.meta);
    parser.parse(PatentMeta.class);
    parser.parse(Patent.class);
    parser.parse(PatentFeature.class);
    parser.parse(PatentContent.class);
    parser.parse(Symbol.class);
    parser.parse(Agency.class);
    parser.parse(PatentAgency.class);
    parser.buildGraph();

    TableMeta m = FetchReqBuilder.meta;

    FetchCond cond= new CompCond(m.column("agency.kind"),"=",new ConstantField(Agency.Category.APPLICANT));
    m.add("ap",m.column("agency.name"),cond);

    cond= new CompCond(m.column("agency.kind"),"=",new ConstantField(Agency.Category.INVENTOR));
    m.add("in",m.column("agency.name"),cond);

    cond= new CompCond(m.column("agency.kind"),"=",new ConstantField(Agency.Category.ASSIGNEE));
    m.add("pa",m.column("agency.name"),cond);

    cond = new CompCond(m.column("symbol.kind"),"=",new ConstantField(Symbol.Category.IPC));
    m.add("ic",m.column("symbol.original"),cond);

    cond = new CompCond(m.column("symbol.kind"),"=",new ConstantField(Symbol.Category.IPC_MAIN));
    m.add("icm",m.column("symbol.original"),cond);

    cond = new CompCond(m.column("symbol.kind"),"=",new ConstantField(Symbol.Category.CPC));
    m.add("cpc",m.column("symbol.original"),cond);

//    cond = new CompCond(m.column("symbol.kind"),"=",new ConstantField(Symbol.Category.UPC));
//    m.add(new ConstraintField("upcs",m.column("symbol.original"),cond));

    cond = new CompCond(m.column("symbol.kind"),"=", new ConstantField(Symbol.Category.BRANCH));
    m.add("br",m.column("symbol.original"),cond);

    cond = new CompCond(m.column("symbol.kind"),"=", new ConstantField(Symbol.Category.EFFECT));
    m.add("ef",m.column("symbol.original"),cond);
  }

  public static void main(String[] args) throws IOException {

    prepare();
    TableMeta m = FetchReqBuilder.meta;
    FetchReqBuilder builder = FetchReqBuilder.instance();
//    builder
//        .selectAs("ab","abstraction").selectAs("pn","claim")
//        .select("ap")
//        .depot(1);
    builder.depot(28L).select("id");
    String sql = builder.build().sql();
    System.out.println(sql);



  }
}
